home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio / Ray Dream Studio (CDRAYD1) (Ray Dream) (1995).iso / DREAMSDK.WIN / INCLUDE / 3DBSTYPE.H next >
Encoding:
C/C++ Source or Header  |  1995-10-30  |  16.5 KB  |  468 lines  |  [TEXT/mdos]

  1. /* $Id: 3Dbstype.h 1.11 1995/10/30 05:54:20 PIERRE Exp $ */
  2. /*****************************************************************************\
  3. *                                                                             *
  4. * 3DBsType.h -     Basic 3D types definition                                               *
  5. *                                                                             *
  6. *   Common to EVX and COM interfacing.                                        *
  7. *   Uses QuickMath unless qUsesQuickMath is false.                            *
  8. *                                                                             *
  9. *           Copyright (c) 1995, Ray Dream, Inc. All rights reserved.          *
  10. *                                                                             *
  11. \*****************************************************************************/
  12.  
  13. #ifndef __3DBSTYPE__
  14. #define __3DBSTYPE__
  15.  
  16. #if 0
  17. #if !defined(ULONG) && !defined(BASETYPES)   // PF: ULONG is defined in COM headers but not in the EVX ones
  18. #define ULONG unsigned long
  19. typedef ULONG *PULONG;
  20. typedef unsigned short USHORT;
  21. typedef USHORT *PUSHORT;
  22. typedef unsigned char UCHAR;
  23. typedef UCHAR *PUCHAR;
  24. typedef char *PSZ;
  25. #define BASETYPES
  26. #endif
  27. #endif
  28.  
  29.  
  30. // QuickMath. We use QMath.h by default
  31. // If you do not want to use QuickMath, define qUsesQuickMath and define the NUM3D;
  32. // VECTOR2D, and VECTOR3D types before including this file.
  33. #ifndef qUsesQuickMath
  34. #define qUsesQuickMath 1
  35. #endif
  36.  
  37. #if qUsesQuickMath
  38. #include "QMath.h"
  39. typedef QuickFix NUM3D;
  40. typedef QuickFixVector2 VECTOR2D;
  41. typedef QuickFixVector3 VECTOR3D;
  42. #endif
  43.               
  44.               
  45. struct I3DShInstance;
  46.  
  47. /** Constants **************************************************/
  48.  
  49. //-- Shading Level
  50. enum ShadingLevel {
  51.     kShLvlNoChanges=-1,     // No Changes - Use renderer’s default shading level
  52.     kShLvlInvisible=0,         // Invisible - Do not render
  53.     kShLvlBBox=1,                 // Render bounding box only
  54.     kShLvlWireFrame=2,        // Wireframe
  55.     kShLvlPreview=3,            // Preview Shading - Fast and crude shading
  56.     kShLvlFullShading=4        // Full Shading
  57.     };
  58.  
  59.  
  60. /** Base types defines **************************************************/
  61. typedef unsigned char BOOLEAN;
  62.  
  63. #ifndef NULL
  64. #define NULL 0
  65. #endif
  66.  
  67. #ifndef TRUE
  68. #define TRUE 1
  69. #endif
  70.  
  71. #ifndef FALSE
  72. #define FALSE 0
  73. #endif
  74.  
  75. /** 3D types defines **************************************************/
  76.  
  77. #ifndef BOX2D
  78. typedef struct BOX2D{
  79.     VECTOR2D        fMin;
  80.     VECTOR2D        fMax;
  81.     } BOX2D; 
  82. #define BOX2D BOX2D
  83. #endif
  84.  
  85. #ifndef BOX3D
  86. typedef struct BOX3D {
  87.     VECTOR3D        fMin;
  88.     VECTOR3D        fMax;
  89.     } BOX3D;
  90. #define BOX3D BOX3D
  91. #endif
  92.  
  93. // The i, j and k vectors
  94. // can be considered as the unit vectors of the Local System,
  95. // and the fix, fiy,... values as they coordinates in the
  96. // Global Coordinates System.
  97. typedef struct MATRIX3D {
  98.     NUM3D fix, fjx, fkx,
  99.                 fiy, fjy, fky,
  100.                 fiz, fjz, fkz;
  101.     } MATRIX3D;
  102.  
  103.  
  104. // Matrix 3 x 3 + translation
  105. typedef struct TRANSFORM3D {
  106.     MATRIX3D        fR;        // Rotation 3 x 3 matrix
  107.     VECTOR3D        fT;        // Translation
  108.     } TRANSFORM3D;
  109.  
  110. // Tree transformation
  111. typedef struct TREETRANSFORM3D {
  112.     MATRIX3D        fR;        // Rotation 3 x 3 matrix
  113.     VECTOR3D        fT;        // Translation
  114.     NUM3D                fS;        // Uniform scaling
  115.     } TREETRANSFORM3D;
  116.  
  117. typedef struct COLOR3D {
  118.     long    Mode;        // Color model. 0=RGB, 1=CMYK
  119.     NUM3D    R;            // Red or Cyan
  120.     NUM3D    G;            // Green or Magenta
  121.     NUM3D    B;            // Blue or Yellow
  122.     NUM3D    A;            // N/A or Black
  123. } COLOR3D;
  124.  
  125. typedef struct RECT3D {
  126.     short        top;
  127.     short        left;
  128.     short        bottom;
  129.     short        right;
  130. } RECT3D;
  131.  
  132. typedef struct VERTEX3D {
  133.     VECTOR3D        fVertex;        // x, y, z vertex coordinates
  134.     VECTOR3D        fNormal;        // Nx, Ny, Nz normal values at that vertex
  135.     NUM3D                fu,fv;            // Texture u,v values at that vertex
  136. } VERTEX3D;
  137.  
  138. typedef struct FACET3D{
  139.     VERTEX3D    fVertices[3];        // The facet three vertices
  140.     short            fUVSpace;                // UV Space ID this facet belongs to
  141.     short            fReserved;            // Reserved - 0
  142.     } FACET3D;
  143.  
  144. typedef struct PATCH3D{
  145.     VECTOR3D    fVertices[4][4];        // The patch 16 vertices
  146.     NUM3D            fu[2];                            // u values at the patch boundaries
  147.     NUM3D            fv[2];                            // v values at the patch boundaries
  148.     short            fUVSpace;                        // UV Space ID this patch belongs to
  149.     short            fReserved;                    // Reserved - 0
  150.     } PATCH3D;
  151.  
  152.  
  153.  
  154. /** Shading defines **************************************************/
  155.  
  156. typedef struct ShadingFlags{
  157.     BOOLEAN    fCallOnce;                    // Constant Shader: The shader needs to be called only once for the whole object or shading area
  158.     BOOLEAN    fNeedsColor;                // Needs Color - Not used
  159.     BOOLEAN    fNeedsPoint;                // Needs surface point in Global Coordinates
  160.     BOOLEAN    fNeedsNormal;                // Needs surface Normal in Global Coordinates
  161.     BOOLEAN    fNeedsIsoU;                    // Needs U iso-parametric vector in Local Coordinates
  162.     BOOLEAN    fNeedsIsoV;                    // Needs V iso-parametric vector in Local Coordinates
  163.     BOOLEAN    fNeedsUV;                        // Needs u,v texture values
  164.     BOOLEAN    fNeedsPointLoc;            // Needs surface point in Local Coordinates
  165.     BOOLEAN    fNeedsNormalLoc;        // Needs surface Normal in Local Coordinates
  166.     BOOLEAN    fNeedsPixelRatio;        // Needs Pixel Ratio - Not used yet - Future use
  167.     BOOLEAN    fChangesNormal;            // The shader changes the Normal. The new Normal will have to be read in ShadingOut::fChangedNormal
  168. } ShadingFlags;
  169.  
  170. typedef struct ShadingIn    { 
  171.     COLOR3D        fColor;                // Color - Not used - For future use
  172.     VECTOR3D    fPoint;                // Surface point in Global Coordinates
  173.     VECTOR3D    fNormal;            // Surface Normal in Global Coordinates
  174.     VECTOR3D    fIsoU;                 // U iso-parametric vector in Local Coordinates
  175.     VECTOR3D    fIsoV;                // V iso-parametric vector in Local Coordinates
  176.     VECTOR2D    fUV;                    // u,v texture values
  177.     unsigned long    fUVSpaceID;        // UV Space ID
  178.     VECTOR3D    fPointLoc;        // Surface point in Local Coordinates
  179.     VECTOR3D    fNormalLoc;        // Surface Normal in Local Coordinates
  180.     NUM3D            fPixelRatio;    // Pixel Ratio - Not used - For future use
  181. } ShadingIn;
  182.  
  183. typedef struct ShadingOut{ 
  184.     COLOR3D        fColor;                        // Diffuse Color (Kd)
  185.     COLOR3D        fSpecularColor;        // Specular Color (Ks)
  186.     NUM3D            fSpecularSize;        // Specular highlight size (Ns)
  187.     NUM3D            fAmbient;                    // Ambient factor (Fa)
  188.     NUM3D            fLambert;                    // Diffuse factor (Fd)
  189.     COLOR3D        fReflection;            // Reflectivity (Rx)
  190.     COLOR3D        fTransparency;        // Transparency (Tx)
  191.     NUM3D            fRefractiveIndex;    // Refraction index (Nr)
  192.     COLOR3D        fGlow;                        // Glow color
  193.     VECTOR3D    fChangedNormal;     // Changed Normal in Global Coordinates
  194. } ShadingOut;
  195.  
  196. typedef struct UVSpaceInfo    {
  197.     unsigned long        fID;        // UV Space ID
  198.     VECTOR2D                fMin;        // UV Space minimum boundaries
  199.     VECTOR2D                fMax;        // UV Space maximum boundaries
  200.     BOOLEAN                 fWraparound[2];        // Tells is the UV Space is closed in the U or V direction
  201.     
  202.     //-- Flat surfaces handling:
  203.     BOOLEAN     fIsFlatSurface;        // TRUE if the object is a flat surface only
  204.     // for xyz to uv
  205.     VECTOR2D     fUVOffset;
  206.     VECTOR3D    fProjU;
  207.     VECTOR3D    fProjV;
  208.     // for uv to xyz
  209.     VECTOR3D    fOffset;
  210.     VECTOR2D    fProjX;
  211.     VECTOR2D    fProjY;
  212.     VECTOR2D    fProjZ;
  213.     } UVSpaceInfo;
  214.  
  215. typedef struct ShadingInOut{
  216.     ShadingIn*         fIn;            // Shading input parameters
  217.     ShadingOut*     fOut;            // Shading output parameters
  218.     UVSpaceInfo*    fUVInfo;    // UV Space information
  219.     unsigned long    fCurrentCompletionMask;    // Internal flags for shaders. Must be set to 0x7F before calling DoShade
  220. } ShadingInOut;
  221.  
  222. typedef struct ShadingElemRect {    // Rectangle in a Shading Element.
  223.     NUM3D fTop;
  224.     NUM3D fLeft;
  225.     NUM3D fBottom;
  226.     NUM3D fRight; 
  227.     } ShadingElemRect;
  228.  
  229. // Shading Element:
  230. // A Shading Element defines an area of Shading on an Object surface.
  231. // The area is defined in the surface UV Space.
  232. // fBBox and fShaderBox define the same rectangle in two different systems. fBBox is
  233. // in the UV Space, and thus defines the extent of the Shading Element on the Object
  234. // surface. fShaderBox defines the boundaries of the UV values that will be passed to
  235. // the Shader. Therefore, moving or rezising the Shading Element on the object surface
  236. // will not change the shading inside the Shading Element (provided that the Shader bases
  237. // its calculations on the UV values. Otherwise the discussion is pointless).
  238. typedef struct ShadingElem {
  239.     ShadingElemRect            fBBox;                // Extent of the Shading Element in the UV Space
  240.     ShadingElemRect            fShaderBox;        // Extent of the Shading Element as seen by the shader
  241.     NUM3D                                 fOpacity;            // Opacity of the Shading Element vs. whatever other Shader Elements may be under
  242.  } ShadingElem;
  243.  
  244. /*****************************************************************************\
  245. *  Lighting Model:                                                            *
  246. *                                                                             *
  247. *                    --                 --                                    *
  248. *                    \                  \             Ns                      *
  249. *    Color = Fa*Kd*Ia + / Fd*Kd*Ii(Li.N) + / Ks*Ii*(Ri.N)    +  Rx*(reflected color) + Tx*(transmitted color)
  250. *                        --i                --i                                   *
  251. *                                                                             *
  252. *   With:                                                                     *
  253. *      Ia: Ambient light color                                                *
  254. *      Ii: Color of the light source #i                                       *
  255. *      Li: Unit vector pointing from the surface point to light source #i     *
  256. *      N : Surface Normal                                                     *
  257. *      Ri: Unit vector giving the reflection direction of the light source #i *
  258. *                                                                             *
  259. *  V1.V2 is a scalar product between 2 vectors:                               *
  260. *      V1.V2 = V1.x*V2.x + V1.y*V2.y + V1.z*V2.z                              *
  261. *                                                                             *
  262. *  Refracted ray direction is computed using Snell's law:                     *
  263. *       Nr1 * Sinus(alpha1) = Nr2 * Sinus(alpha2)                             *
  264. *                                                                             *
  265. *                                                                             *
  266. \*****************************************************************************/
  267.  
  268.  
  269. /** Ray-tracing defines **************************************************/
  270.  
  271. typedef struct Ray3D{
  272.     VECTOR3D    fOrigin;                // Origin of the ray
  273.     VECTOR3D    fDirection;            // Direction of the ray
  274.     NUM3D            fFocalPoint;        // ???
  275.     NUM3D            fAngle;                    // ???
  276.     NUM3D            fWidthAtFocal;    // ???
  277. } Ray3D;
  278.  
  279. typedef struct RayHit3D{
  280.     VECTOR3D        fPosition;                // Intersection point in Global Coordinates
  281.     VECTOR3D        fNormal;                    // Normal at that point in Global Coordinates
  282.     VECTOR2D        fUV;                            // (u,v) texture values at that point
  283.     NUM3D                ft;                                // t parameter along the ray: fPosition = RayOrigin + t * RayDirection
  284.     VECTOR3D        fIsoU;                        // Isoparametric U vector in the Object Local Coordinates
  285.     VECTOR3D        fIsoV;                        // Isoparametric V vector in the Object Local Coordinates
  286.     void*                fPrivate1;                // Private data for renderer.
  287.     void*                fPrivate2;                // Private data for renderer
  288.     void*                fPrivate3;                // Private data for renderer
  289.     BOOLEAN            fShouldSetUV;            // TRUE if fUV should be set
  290.     BOOLEAN            fShouldSetIsoUV;    // TRUE if fIsoU and fIsoV should be set
  291.     BOOLEAN            fHasSetPosition;    // TRUE if fPosition was set
  292.     BOOLEAN            fHasSetNormal;        // TRUE if fNormal was set
  293.     BOOLEAN            fHasSetUV;                // TRUE if fUV was set
  294.     BOOLEAN            fHasSetIsoUV;            // TRUE if fIsoU and fIsoV were set
  295. } RayHit3D;
  296.  
  297. typedef BOOLEAN (*FilterHitProc) (I3DShInstance* instance);
  298.  
  299. typedef struct RayHitParameters {
  300.     NUM3D     tmin;
  301.     NUM3D     tmax;
  302.     BOOLEAN    fShouldSetS;
  303.     BOOLEAN    fShouldSetUV;
  304.     BOOLEAN    fZBShading;
  305.     BOOLEAN    fNoGrid;
  306.     void *fFilterInstance;
  307. } RayHitParameters;
  308.  
  309. typedef struct HitInfo {
  310.     //-- Output data:
  311.     I3DShInstance*    fInstance;        // Instance that was hit by the ray
  312.     VECTOR2D        fUV;                            // (u,v) texture values at the intersection point
  313.     unsigned long                fUVSpaceID;                // UV Space ID
  314.     VECTOR3D         fPosition;                // Intersection point in Global Coordinates
  315.     VECTOR3D         fNormal;                    // Normal at that point in Global Coordinates
  316.     COLOR3D            fColor;                        // Rendered final color (all lighting and shading included)
  317.     NUM3D                fAlpha;                        // Alpha-channel value
  318.     unsigned long                fIndex;                        // Instance unique index
  319.     NUM3D                fDistance;                // Distance from the point of view to the intersection point
  320.     
  321.     //-- Input flags:
  322.     BOOLEAN    fNeedsColor;                    // Needs fColor
  323.     BOOLEAN    fNeedsDistance;                // Needs fDistance
  324.     BOOLEAN    fNeedsPosition;                // Needs fPosition
  325.     BOOLEAN    fNeedsNormal;                    // Needs Normal
  326.     BOOLEAN    fNeedsAlpha;                    // Needs Alpha
  327.     BOOLEAN    fNeedsIndex;                    // Needs Intance index
  328.     BOOLEAN    fNeedsUV;                            // Needs (u,v) values
  329.     BOOLEAN    fZBShading;                        // Ask for Z-Buffer-like shading: no transparencies, no reflections and no shadows
  330.     FilterHitProc fFilterInstanceProc;    //Filterproc for instances. used only in fast hit mode when fNeedsColor is false
  331.     } HitInfo;
  332.  
  333. typedef void (*RayHitCallback)(Ray3D* aR, NUM3D tmin, NUM3D tmax, RayHit3D* hit, void* privData);
  334. typedef void (*RayTraceCallback)(HitInfo* hitInfo, void* privData);
  335.  
  336.  
  337. //*********************************************************************************
  338.  
  339. class SDGraphicDevice;
  340. struct I3DShInstance;
  341. typedef void (*EnumPatchesCallback) (PATCH3D* patch, void* privData);
  342. typedef void (*EnumFacetsCallback) (FACET3D* facet, void* privData);
  343.  
  344. typedef struct GBufferData {
  345.     void* data;
  346.     long channelBits;
  347.     long channelOffsetBits;
  348.     long columnBits;
  349.     long rowBits;
  350.     short nbrChannels;
  351.     } GBufferData;
  352.  
  353. typedef struct GBuffer {
  354.     GBufferData color;
  355.     GBufferData distance;
  356.     GBufferData position;
  357.     GBufferData normal;
  358.     GBufferData alpha;
  359.     GBufferData index;
  360.     GBufferData surface;
  361.     } GBuffer;
  362.  
  363. typedef struct LightTraceElement {
  364.     VECTOR3D fPoint1;
  365.     VECTOR3D fVector1;
  366.     VECTOR3D fPoint2;
  367.     VECTOR3D fVector2;
  368. } LightTraceElement;
  369.  
  370.  
  371. //****** Parameter blocks for building extrusions ******************************
  372.  
  373. #ifdef __cplusplus
  374. class I3DShCrossSection;
  375. #else
  376. typedef void* I3DShCrossSection;
  377. #endif
  378.  
  379.  
  380. typedef struct Path3DPoint {
  381.     VECTOR3D            fVertex;                // Vertex
  382.     // Fill these only if using envelopes:
  383.     VECTOR3D            fTopEnv;                // Envelope: top curve on right wall
  384.     VECTOR3D            fBotEnv;                // Envelope: bottom curve on right wall
  385.     VECTOR3D            fLeftEnv;                // Envelope: left curve on floor
  386.     VECTOR3D            fRightEnv;            // Envelope: right curve on floor
  387.     } Path3DPoint;
  388.  
  389. typedef struct ExtrusionHeaderPB {
  390.     Path3DPoint                f3DPathPrevControl1;        // Don't fill this if 1st section
  391.     Path3DPoint                f3DPathPrevControl2;        // Don't fill this if 1st section
  392.     VECTOR3D                    f3DPathVertex;                    // Put 0 in x and z unless you know what you're doing
  393.     BOOLEAN                        fFill;
  394.     BOOLEAN                        fSkinToNext;
  395.     } ExtrusionHeaderPB;
  396.  
  397. typedef struct ExtrusionPB {        // Adding a non-automatic cross-section
  398.     ExtrusionHeaderPB        fHeader;
  399.     //-- Specific parameters:
  400.     I3DShCrossSection*    fCrossSection;
  401.     NUM3D                                fTwisting;            // Twisting angle
  402.     } ExtrusionPB;
  403.  
  404. typedef struct ExtrusionAutoPB {        // Adding an automatic cross-section
  405.     ExtrusionHeaderPB        fHeader;
  406.     //-- Specific parameters:
  407.     NUM3D                                fTopScaling;
  408.     NUM3D                                fBotScaling;
  409.     NUM3D                                fLeftScaling;
  410.     NUM3D                                fRightScaling;
  411.     } ExtrusionAutoPB;
  412.  
  413. // Envelope flags:
  414. enum { kExtrFree=0,             // Free Envelope
  415.                 kExtrSym=1,             // Symetrical Envelope
  416.                 kExtrSemiSym=6};    // Semi-symetrical Envelope
  417.  
  418.  
  419. //-- Old EVX naming compatibility box - to become obsolete in the near future
  420. #ifdef __EVXCOMPATIBILITY__
  421. #define MTRay Ray3D
  422. #define MTRayHit RayHit3D
  423. #define THitInfo HitInfo
  424. #define MTShFlags ShadingFlags
  425. #define TShadingIn ShadingIn
  426. #define TShadingOut ShadingOut
  427. #define TShadingElem ShadingElem
  428. #define TUVSpaceInfo UVSpaceInfo
  429. #define MTShadingIO ShadingInOut
  430. #define RayHitParams RayHitParameters
  431. #ifndef TINSTANCE
  432. #ifndef __cplusplus
  433. #define TINSTANCE void
  434. #else
  435. class TInstance;
  436. #define TINSTANCE TInstance
  437. #endif
  438. #endif
  439. #define ShRect ShadingElemRect
  440. #define TRANSCALE TREETRANSFORM3D
  441. #define TRANSFORM TRANSFORM3D
  442. #define MAT33 MATRIX3D
  443. #define FIXED NUM3D
  444. #define VECTOR2 VECTOR2D
  445. #define VECTOR3 VECTOR3D
  446. #define TVertex VERTEX3D
  447. #define TFacette FACET3D
  448. #define TPatch PATCH3D
  449. #define COLOR COLOR3D
  450. #define RECT RECT3D
  451. #define TLightTraceElement LightTraceElement
  452.  
  453.  
  454. #ifdef _WIN31
  455. #define RDXAPI __cdecl __loadds
  456. #define RDXAPITYPE __cdecl
  457. #else
  458. #define RDXAPI
  459. #define RDXAPITYPE
  460. #define __cdecl
  461. #define __loadds
  462. #endif
  463.  
  464. #endif // __EVXCOMPATIBILITY__
  465.          
  466. #endif
  467.  
  468.